{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from PIL import Image\n",
    "import numpy as np\n",
    "\n",
    "import matplotlib.pyplot as plt\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def cal_vdvi(image):\n",
    "    pass\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "image_path = \"../datasets/tianchi_no/image/image_10_256.png\"\n",
    "image = Image.open(image_path).convert(\"RGB\")\n",
    "\n",
    "# image = np.asarray(image)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1.8125     0.98347107 0.82312925 ... 0.47368421 0.472      0.44444444]\n",
      " [1.16       0.93650794 0.92481203 ... 0.47096774 0.46875    0.46534653]\n",
      " [0.77483444 0.68786127 0.70760234 ... 0.51048951 0.50819672 0.44761905]\n",
      " ...\n",
      " [0.06329114 0.23076923 0.10144928 ... 0.04       0.025      0.00645161]\n",
      " [0.10091743 0.48148148 0.07936508 ... 0.025      0.01234568 0.        ]\n",
      " [0.09734513 0.04       0.41176471 ... 0.01234568 1.44067797 1.27135678]]\n"
     ]
    }
   ],
   "source": [
    "# plt.imshow(image[:,:, 2])\n",
    "# print(image.shape)\n",
    "\n",
    "\n",
    "\n",
    "def calc_vdvi(image):\n",
    "    r, g, b = image.split()\n",
    "    r = np.asarray(r)\n",
    "    g = np.asarray(g)\n",
    "    b = np.asarray(b)\n",
    "    numerator = 2 * g - r - b\n",
    "    denominator = 2 * g + r + b\n",
    "    denominator[denominator == 0] = 1\n",
    "    # 分子\n",
    "    return numerator / denominator\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "3fd1c1a712e1abf08a169895ba360db48308ba1fce9a1b9e5618255bfa77d7d2"
  },
  "kernelspec": {
   "display_name": "Python 3.7.11 64-bit ('torch': conda)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
